<template>
	<sl-page title="门店" :safeBottom="false">
		<List :listDatas="stores" @list:click="handleSetDefault">
			<template v-slot="{ item }">
				<view>
					<view class="p-1">{{ item.name }}</view>
					<view class="flex p-1">
						<u-icon name="map"></u-icon>
						<view class="px-1">{{ item.address }}</view>
					</view>
				</view>
			</template>
		</List>
	</sl-page>
</template>

<script>
import * as Util from '@/utils/index.js';
import TenantApi from '@/api/tenant/tenant.js';
import List from '@/pages/components/list/list.vue';

export default {
	//
	// mixins: [Scroll],
	//
	components: {
		List
	},
	//
	data() {
		return {
			//当前页面参数
			options: {},
			//正在加载
			isLoading: true,
			//商铺Id
			tenantId: '',
			//门店
			stores: []
		};
	},
	//
	onLoad(options) {
		this.options = options;
	},
	//
	onShow() {
		this.initPara();
		this.getPageData();
	},
	//
	methods: {
		//
		initPara() {
			if (this.options.tenantId && this.options.tenantId !== '') {
				this.tenantId = this.options.tenantId;
			} else {
				this.tenantId = '';
			}
			console.log('this.tenantId--------------: ', this.tenantId);
		},
		//
		getPageData() {
			const app = this;
			app.isLoading = true;
			app.loadStore();
			app.isLoading = false;
		},
		//获取自提地址
		loadStore: async function() {
			let res = await TenantApi.stores(this.tenantId);
			this.stores = res.obj || [];
			console.log('this.stores: ', this.stores);
			// return res.obj || {};
		},
		/**
		 * 设置为默认地址
		 * @param {Object} id 收货地址ID
		 */
		handleSetDefault(item) {
			console.log('item: ', item);
			let pages = getCurrentPages();
			let prevPage = pages[pages.length - 2]; //上一个页面
			prevPage.$vm.getStoreCallback(item); //重点$vm
			uni.navigateBack();
		}
	}
};
</script>

<style lang="scss" scoped></style>
